/**
 * Tiem: 2023-2-9
 * FileName: SearchHeader
 * Editor: Haidong
 */

import React, { useRef } from 'react';
import { Form, Input, Space, Button, Select, DatePicker } from 'antd';
import _ from 'lodash';
import TheButton from "@/components/TheButton";
import { SearchOutlined } from '@ant-design/icons';
import { getDateTime3 } from '@/utils/getDate';

const { RangePicker } = DatePicker

const SearchHeader = ({ getValue, orderCode }) => {
  const formRef = useRef()
  const orderCode11 = orderCode
  const onFinish = (values) => {
    if (values.time && values.time.length) {
      values.createTimeStart = getDateTime3(values.time[0]) + ' 00:00:00'
      values.createTimeEnd = getDateTime3(values.time[1]) + ' 23:59:59'
    }
    delete (values.time)
    _.forIn(values, (v, k) => {
      if (!v) {
        delete (values[k])
      }
    })
    getValue(values)
  }
  const reset = () => {
    formRef.current.setFieldsValue({
      memberName: "",
      orderCode: '',
      shopSalesReturnId: '',
      time: []
    })
    getValue({})
  }
  return (
    <Form ref={formRef} onFinish={onFinish} layout="inline" initialValues={{
      orderCode: orderCode11
    }}>

      <Form.Item name="orderCode">
        <Input style={{ width: 140 }} placeholder='输入搜索关键字' suffix={<SearchOutlined />} />
      </Form.Item>
      <Form.Item name="time" label="预约时间">
        <RangePicker placeholder={['开始时间', '结束时间']} />
      </Form.Item>
      <Form.Item name={"productStatus"} label="预约状态">
        <Select
          style={{ width: 120 }} allowClear
          options={[{ value: 'Y', label: '全部' }, { value: 'N', label: '待支付' }, { value: 'G', label: '待确认' }, { value: 'G', label: '已确认' }, { value: 'G', label: '已完成' }, { value: 'G', label: '已关闭' }]}
          placeholder={"请选择"}
        />
      </Form.Item>
      <Form.Item name={"productStatus"} label="是否有退款">
        <Select
          style={{ width: 120 }} allowClear
          options={[{ value: 'Y', label: '是' }, { value: 'N', label: '否' }]}
          placeholder={"请选择"}
        />
      </Form.Item>
      <Form.Item>
        <Space>
          <Button htmlType="submit" type="primary">搜索</Button>
          <Button onClick={reset}>重置</Button>
        </Space>
      </Form.Item>
      {/* <TheButton type="default" size="middle" hasPermi={['commodity:list:exportGoodsBySku']} onClick={this.props.toExport}>导出商品</TheButton> */}
    </Form>
  );
}

export default SearchHeader